﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessLogic.BusinessEntity.Entities;


namespace UserInterface.ClientApplication.UIEntity
{
	[Serializable]
	public class RemittanceAdviceView
	{
		private string status;
		public int ID { get; set; }

		public string Number { get; set; }

		public string RejectionReason { get; set; }

		public AccountView PayerPartyAccount { get; set; }

		public AccountView BillToPartyAccount { get; set; }

		public CurrencyView Currency { get; set; }


		public string Status
		{
			get
			{
				switch (status)
				{
					case "Pending":
						return "Ожидание";
					case "ReadyToSign":
						return "Готово к отправке";
					case "Received":
						return "Принято";
					case "Sent":
						return "Отправлено";
					case "NotAccepted":
						return "Ошибка при обработке";
					case "Processed":
						return "Оплачено";
					default:
						return status;
				}

			}
			set
			{
				status = value;
			}
		}

		public string Description { get; set; }

		public decimal TotalAmount { get; set; }

		public DateTime IssueDate { get; set; }

		public int DocumentEnvelopeID { get; set; }

		public RemittanceAdviceView()
		{
			
		}

		public RemittanceAdviceView(RemittanceAdvice ra)
		{
			ID = ra.ID;
			Number = ra.Number;
			PayerPartyAccount = new AccountView(ra.PayerPartyAccount);
			BillToPartyAccount = new AccountView(ra.BillToPartyAccount);
			Currency = new CurrencyView(ra.Currency);
			Status = ra.Status.ToString();
			Description = ra.Description;
			TotalAmount = ra.TotalAmount;
			IssueDate = ra.IssueDate;
		}

		public RemittanceAdvice ToBE()
		{
			RemittanceAdvice ra = new RemittanceAdvice();
			ra.Number = Number;
			if(PayerPartyAccount != null)
				ra.PayerPartyAccount = PayerPartyAccount.ToBE();
			if(BillToPartyAccount.ToBE() != null)
				ra.BillToPartyAccount = BillToPartyAccount.ToBE();
			ra.Currency = Currency.ToBE();
			ra.Status = (RemittanceAdviceStatus)Enum.Parse(typeof(RemittanceAdviceStatus), status); 
			ra.Description = Description;
			ra.TotalAmount = TotalAmount;
			ra.IssueDate = IssueDate;
			return ra;
		}

		public string GetOriginalStatus()
		{
			return status;
		}

		public RemittanceAdviceView Copy()
		{
			var ra = new RemittanceAdviceView();
			ra.ID = ID;
			ra.Number = Number;
			ra.PayerPartyAccount = PayerPartyAccount;
			ra.BillToPartyAccount = BillToPartyAccount;
			ra.Currency = Currency;
			ra.Status = status;
			ra.Description = Description;
			ra.TotalAmount = TotalAmount;
			ra.IssueDate = IssueDate;
			return ra;
		}
	}
}
